package cn.ac.iscas.domain.job;

import cn.ac.iscas.domain.EnumVal;
import com.iscas.datasong.lib.util.DataSongStringUtils;

/**
 * Created by ISCAS on 2017/9/27.
 *
 * 同步任务执行状态
 *
 * 任务状态简单处理，只有正在执行和等待状态的不允许编辑，其他状态可以编辑
 */
public enum JobStatus implements EnumVal {
/*	Waiting(0),//待执行
	Running(1),//正在执行
	Success(2),//已执行
	Failed(3);//执行失败
//	Suspend(4);//暂停*/

	UNSUBMITTED(10), //待提交，草稿状态
	WAITING(20),	   //等待执行，或等待再次执行
	RUNNING(30),    //正在执行
	PAUSE(50),     //终止执行
	FAILED(60),     //执行失败
	SUCCEEDED(70);  //成功执行

	private int value;

	JobStatus(int value){
		this.value = value;
	}

	@Override
	public Object value() {
		return value;
	}


	public boolean isFinished() {
		return this == PAUSE || this == FAILED || this == SUCCEEDED;
	}

	public boolean isRunning() {
		return this == RUNNING || this == WAITING ;
	}

	static public JobStatus analyze(String value){
		if(DataSongStringUtils.isEmpty(value)){
			return JobStatus.UNSUBMITTED;
		}

		for(JobStatus jobStatus : JobStatus.values()){
			if(jobStatus.name().toUpperCase().equals(value.toUpperCase())){
				return jobStatus;
			}
		}

		return JobStatus.UNSUBMITTED;
	}
}
